<?php
namespace app\api\controller\v1\model\distance;

use think\Model;
use think\Db;

class Distance extends model
{
    //插入用户
    public function getInsertMap($latitude,$longitude,$user_id){

        $data = array(
            'user_id' => $user_id,
            'loc' => array(
                'type' => 'Point',
                'coordinates' => array(doubleval($longitude), doubleval($latitude))
            )
        );

        $result = Db::connect("db_mongo")->name("yunmiao_location")->where(['user_id' => $user_id])->select();

        if (!$result) {
            $m = Db::connect("db_mongo")->name("yunmiao_location")->insertGetId($data);
        }else{
            Db::connect("db_mongo")->name("yunmiao_location")->where(['user_id' => $user_id])->delete();
            $m = Db::connect("db_mongo")->name("yunmiao_location")->insertGetId($data);

        }

        return $m;
    }


//广告图片
    public function getAdsImg(){
        $result = Db::query("select ads_img_url from ym_ads_img");
        $length = count($result);
        $img = [];
        for ($i=0; $i < $length; $i++) {
            $img[] = $result[$i]['ads_img_url'];
        }
        return $img;
    }











}